DrawPaletteMappedByte
DrawPaletteMappedByte Xpos, Ypos, ThisByte, Shift, Mask, Length
 
Parameters:

    Xpos = The output X coordinate of this group of pixels
    Ypos = The output Y coordinate of this group of pixels
    ThisByte = The byte to process and drawn
    Shift = The shift to perform between bits.
    Mask = Mask to apply to the colour index before reading the palette.
    Length = Number of pixels in this byte
Returns: NONE
 

     DrawPaletteMappedByte reads either indivual bits or groups of bits within a byte and uses these groups as colour indexes to the user defined colour palette (SetPalette). So it grabs the bit(s) looks in the palette array for a RGB colour, then draws this colour to the current surface.


     Using this command we can simulate a classic 8bit (256 colour) screen mode, and effects like raster bars, mirrors and glez vectors to name a few.



FACTS:


      * The DrawPaletteMappedByte is just like the FastDot/FastPoint commands and doesn't include surface locking/clipping internally. So it expects the current output surface has been seeded and the coordinates you give it are legal. If not, you should expect it to crash.

      * DrawPaletteMappedByte is useful for displaying image data from retro computer systems and image formats.



Example:


      This following example creates simplified mock up of the Commodore 64 screen, or C64 for short. The C64 was an 8bit home computer system that was popular in 1980's, it's still popular today actually. The display hardware of the C64 might seem simple by todays standards, but it's not that easy re-create such display on modern RGB displays.Modern systems generally use byte/word/integer per pixel RGB displays, where retro hardware tends to use groups of bits within a byte to represent a group of 8 colours.

      Bellow we're creating a simplified 2bit C64 styled display. In these modes the graphics hardware in the C64 would interpret each of those 8bits as individual pixels. So a set bit would be drawn in one colour and clear bit was drawn in another. We could do this manually, but it's a lot of work for PlayBASIC runtime to perform, so we added the DrawPaletteMappedByte to do the job for you.


 
Example Source: Download This Example
  // Limit the Refresh Rate to 50 or less
  SetFPS 50
  
  
  // include the palette mapping library
  #Include "PaletteMapping"
  
  // load a more attractive windows font
  LoadFont "verdana",2,24,0,8
  
  
  // delcare our array that will hold our array of colour values
  Dim Palette($ffff)
  
  // point the palette mapping functions to the address of our palette array
  SetPalette(Palette())
  
  // Fill in some colours
  Palette(0)=$3E31A2
  Palette(1)=$7C70DA
  Palette(2)=$00ffff
  Palette(3)=$0000ff
  
  
  // Load the characters into a bank
  CharMapRomBank=LoadFileToBank("gfx\Char.rom")
  
  
  // CReate FX image that we'll be drawing onto
  Screen=NewImage(320,200,2)
  
  
  
  // ------------------------------------
  // Start of main loop
  // ------------------------------------
  Do
     
   ; clear the PB screen with colour index 1 from the palette
     Cls palette(1)
     
   ; Draw out mock up of the C64 hires screen
     Gosub Draw_Mock_Up_C64_Screen
     
     
   ; draw a scaled version of the mock up c64 screen to the
   ; real screen
     RenderToScreen
     DrawRotatedImage  Screen,80,96,0,2,2,0,0,false
     
     
     SetFont 2
     LockBuffer
     Print "Screen Resolution:"+Str$(Xpos)+"*"+Str$(Ypos)
     Print "Fps:"+Str$(FPS())
     
     CenterText 400,400,"PlayBASIC never forgets !! :)"
     UnLockBuffer
     
     Sync
  Loop
  
  
  
  
  
  // ----------------------------------------------------------------------------
  // ----------------------------------------------------------------------------
Draw_Mock_Up_C64_Screen:
  // ----------------------------------------------------------------------------
  // ----------------------------------------------------------------------------
  Address&=$7ff
  
  
  Ypos=0
  
  RenderToImage screen
  LockBuffer
  ThisRgb=Point(0,0)
  For ChrYLP =1 To 200/8
     
     Xpos =0
     
     // Pre-compute the Y coordinates
     Ypos1=Ypos
     Ypos2=Ypos+1
     Ypos3=Ypos+2
     Ypos4=Ypos+3
     Ypos5=Ypos+4
     Ypos6=Ypos+5
     Ypos7=Ypos+6
     Ypos8=Ypos+7
     
     For ChrXLP=1 To 320/8
        // grab 4 bytes from char rom bank.
        ThisLong=PeekBankInt(CharMapRomBank,Address)
        Address+=4
        
        // Draw each byte as 8 hires pixels (2 colour)
        DrawPaletteMappedByte(Xpos,Ypos1, ThisLong,1,%00000001,8)
        DrawPaletteMappedByte(Xpos,Ypos2, ThisLong/$100,1,%00000001,8)
        DrawPaletteMappedByte(Xpos,Ypos3, ThisLong/$10000,1,%00000001,8)
        DrawPaletteMappedByte(Xpos,Ypos4, ThisLong/$1000000,1,%00000001,8)
        
        // Grab the next 4 bytes from the char rom
        ThisLong=PeekBankInt(CharMapRomBank,Address)
        Address+=4
        // Draw each byte as 8 hires pixels (2 colour)
        DrawPaletteMappedByte(Xpos,Ypos5, ThisLong,1,%00000001,8)
        DrawPaletteMappedByte(Xpos,Ypos6, ThisLong/$100,1,%00000001,8)
        DrawPaletteMappedByte(Xpos,Ypos7, ThisLong/$10000,1,%00000001,8)
        DrawPaletteMappedByte(Xpos,Ypos8, ThisLong/$1000000,1,%00000001,8)
        
        
        Xpos+=8
     Next
     
     Address&=$7ff
     Ypos+=8
  Next
  UnLockBuffer
  
  
  Return
  
  
  
  
  
  
Function LoadFileToBank(Filename$)
  If FileExist(Filename$)
     Size=FileSize(Filename$)
     ThisBank=NewBank(Size+100)
     fh=ReadNewFile(Filename$)
     If fh
        ReadMemory fh,GetBankPtr(ThisBank),Size
        CloseFile fh
     EndIf
  EndIf
EndFunction ThisBank
  
  
  
  
 
Related Info: ARGB | DrawPaletteMappedStrip16 | DrawPaletteMappedStrip8 | IndexToRGB | RGBtoINDEX | SetPalette :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com